﻿@model List<SuperiorModel.Api_ConsigneeModel>
@{
    ViewBag.Title = "地址列表";
    Layout = "~/Views/Shared/_Layout.cshtml";
    var spid = Request["spid"];
    var said = Request["said"];
    var sure = ViewBag.Sure;
}
<header class="wy-header">
    <div class="wy-header-icon-back"><a href="javascript:history.go(-1)"><span></span></a></div>
    <div class="wy-header-title">地址管理</div>
</header>
<div class="weui-content">
    <div class="weui-panel address-box">
        @foreach (var item in Model)
        {
            <div class="weui-panel__bd">
                <div class="weui-media-box weui-media-box_text address-list-box">
                    <a href="/ConSignee/Edit?id=@item.Id&spid=@spid&said=@said" class="address-edit"></a>
                   
                    <h4 class="weui-media-box__title userAddress" aid="@item.Id"><span>@item.ConsigneeName</span><span>@item.ConsigneePhone</span></h4>
                    <p class="weui-media-box__desc address-txt">@item.Address</p>
                    @if (item.IsDefault == 1)
                    {
                        <span class="default-add">默认地址</span>
                    }
                    else
                    {
                        <span style="background: dodgerblue;" class="default-add setDefault" aid="@item.Id" >设置默认并选择</span>
                    }

                </div>
            </div>
        }



    </div>
    <div class="weui-btn-area">
        <a class="weui-btn weui-btn_primary" href="/ConSignee/Add?spid=@spid&said=@said" id="showTooltips"><span class="icon icon-36 ic_25"></span>添加收货地址</a>
    </div>
</div>

<script src="~/scripts/jquery.cookie.js"></script>
<script>
    var spid = ToolManager.Common.UrlParms("spid");
    var said = ToolManager.Common.UrlParms("said");
    $(document).on('click', '.userAddress', function () {
        if (confirm("将会选择当前地址")) {
            var aid = $(this).attr("aid");
            //不能直接返回上一页刷新，因为如果操作了编辑或添加，上一页就不是sureOrder了
            var _orderUrl = $.cookie("SUREURL")
            var url = ToolManager.Common.ReplaceParamVal(_orderUrl, "addresid", aid);
            window.location.href = url;
        }
     
    })
    $(document).on('click', '.setDefault', function () {
        var aid = $(this).attr("aid");
        var index = layer.load(1);
        $.get("/ConSignee/UpdateIsDefault?id=" + aid + "&isdefault=1&spid="+spid+"&r=" + new Date().getTime(), function (data) {
            layer.close(index);
            if (data.IsSuccess) {
                var _orderUrl = $.cookie("SUREURL")
                var url = ToolManager.Common.ReplaceParamVal(_orderUrl, "addresid", aid);
                window.location.href = url;
            } else {
                layer.msg(data.Message);
            }
        });
    })
</script>